/**
 * 
 */
package edu.pw.treegrid.server.message;

import java.util.List;

import edu.pw.treegrid.server.filter.Filter;
import edu.pw.treegrid.server.reportmodel.Report;
import edu.pw.treegrid.server.reportmodel.ReportColumn;

/** 
 * Wiadomosc wysylana przez klienta w przypadku pobierania dziecia danego wezla.
 * @author Piotrek
 */
public class Request {
	private Filter filter;

	public Filter getFilter() {
		return filter;
	}

	public void setFilter(Filter filter) {
		this.filter = filter;
	}

	private Hierarchy hierarchy;

	public Hierarchy getHierarchy() {
		return hierarchy;
	}

	public void setHierarchy(Hierarchy hierarchy) {
		this.hierarchy = hierarchy;
	}

	private Report report;

	public Report getReport() {
		return report;
	}

	public void setReport(Report report) {
		this.report = report;
	}

	/** 
	 * Sciezka identyfikujaca obiekt, dla ktorego zostanie zwrocona lista dzieci.
	 */
	private Path path;

	public Path getPath() {
		return path;
	}

	public void setPath(Path path) {
		this.path = path;
	}
	
	public ReportColumn getCurrentReportColumn() {
		if(isLeafRequest()) {
			return null;
		}
		
		List<Object> p = path.getPath();
		List<ReportColumn> columns = hierarchy.getGroupColumns();
		
		return columns.get(p.size() - 1);
	}
	
	/**
	 * Zwraca true jezeli jest to zadanie pobierajace ostatnie poziom hierarchii.
	 * 
	 * @return
	 */
	public boolean isLeafRequest() {
		List<Object> p = path.getPath();
		List<ReportColumn> columns = hierarchy.getGroupColumns();
		
		return p.size() > columns.size();
	}
}